package service;
import Shiti.Userti;
import dao.DingdanDao;
import dao.UserDao;
public class Userservice {
    UserDao userDao=new UserDao();
    //注册
    public boolean zhuce(Userti userti){
        boolean a=userDao.add(userti);
        return a;
    }
    //登录
    public boolean denglu(Userti userti){
        boolean a= userDao.denglu(userti);

        return a;
    }
    //管理员登录
    public boolean guandengli(Userti userti){
        boolean a= userDao.guandenglu(userti);
        if (a){
            System.out.println("登录成功");
        }else {
            System.out.println("登录失败");
        }
        return  a;
    }
    //查看自己的信息
    public  Userti zicha(int acc,String psw){
        Userti userti =userDao.queryone1(acc,psw);
        return userti;
    }
    //管理员查看用户
    public  Userti cha(int acc){
        Userti userti=userDao.query(acc);
        return userti;
    }
    //删除用户
    public  boolean dele(Userti userti){
        Userti userti1=userDao.query(userti.getAcc());
        boolean a;
        DingdanDao dingdanDao =new DingdanDao();
        if (userti.getPsw().equals(userti1.getPsw())){
            a =userDao.dele(userti);
                if (a){
                    dingdanDao.dele1(userti1);
                     System.out.println("删除成功");
                  }else {
                     System.out.println("删除失败");
                        }
        }else
        {
            a=false;
        }
        return  a;
    }
    //更改用户密码
    public  boolean changepsw(Userti userti,String psw){
        boolean a=userDao.changepsw(userti,psw);
        if (a){
            System.out.println("psw更改成功");
        }else {
            System.out.println("psw更改失败");
        }
        return a;
    }
    //更改用户name
    public  boolean changename(Userti userti,String name){
        boolean a=userDao.changepsw(userti,name);
        if (a){
            System.out.println("name更改成功");
        }else {
            System.out.println("name更改失败");
        }
        return a;
    }
}
